using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AnalysisServices.AdomdServer;

namespace ISV_1.ASClientExtensions
{
    public class SessionMgr
    {
        public SessionMgr()
        {
            Context.CurrentConnection.CubeOpened += new EventHandler(CubeOpened);
            Context.CurrentConnection.CubeClosing += new EventHandler(CubeClosing);
        }

        ~SessionMgr()
        {
        }

        public void CubeOpened(object sender, EventArgs e)
        {
            String username = Context.CurrentConnection.User.Name;
            username = username.Substring(username.IndexOf('\\')+1).ToLowerInvariant();
            //Verify and set user experience for opened cube
            //i.e. define calculated members according to user profile
            AuthoringAndManagement.DefineMembers(Context.CurrentDatabaseName, Context.CurrentCube.Name, username);
            //i.e. define KPIs according to user profile
            AuthoringAndManagement.DefineKPIs(Context.CurrentDatabaseName, Context.CurrentCube.Name, username);
            //i.e. define sets according to user profile
            AuthoringAndManagement.DefineSets(Context.CurrentDatabaseName, Context.CurrentCube.Name, username);

        }

        public void CubeClosing(object sender, EventArgs e)
        {
            //Close and discard any object that requires clean-up
        }

    }
}

